﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using JohnnySins.DAL;
using JohnnySins.DAL.Repositories;
using JohnnySins.Entities;
using JohnnySins.Code;

namespace JohnnySins
{
    public partial class MyVideos : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        public void LoadData()
        {
            using (var repo = RepositoryFactory.ResolveRepository<MyVideoRepository>())
            {
                rptScene.DataSource = repo.FindActive(true, false);
                rptScene.DataBind();
            }
        }

        protected void rptScene_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                MyVideo rowView = e.Item.DataItem as MyVideo;
                string url = "~/Member/DownloadMyVideo.aspx?fileid={0}&q={1}&os={2}";
                
                /*HtmlAnchor lnk = e.Item.FindControl("hlHDQT") as HtmlAnchor;
                if (!string.IsNullOrEmpty(rowView.HDQTFileName))
                    lnk.HRef = string.Format(url, rowView.MyVideoId, "hd", "qt");
                else
                    lnk.Visible = false;

                lnk = e.Item.FindControl("hlHDWin") as HtmlAnchor;
                if (!string.IsNullOrEmpty(rowView.HDWinFileName))
                    lnk.HRef = string.Format(url, rowView.MyVideoId, "hd", "win");
                else
                    lnk.Visible = false;

                lnk = e.Item.FindControl("hlLDQT") as HtmlAnchor;
                if (!string.IsNullOrEmpty(rowView.LDQTFileName))
                    lnk.HRef = string.Format(url, rowView.MyVideoId, "ld", "qt");
                else
                    lnk.Visible = false;

                lnk = e.Item.FindControl("hlLDWin") as HtmlAnchor;
                if (!string.IsNullOrEmpty(rowView.LDWinFileName))
                    lnk.HRef = string.Format(url, rowView.MyVideoId, "ld", "win");
                else
                    lnk.Visible = false;*/
                                
            }
        }
    }
}